<html>
<head>

    <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
    <title>主页</title>
   <script>
       $(function(){
           //注册一个delBtn删除按钮事件
           $("#delBtn").click(function () {
               //包装集的序列号
               //格式：cb=331b57547cc511e78bf71c1b0daf345d&cb=331b96d67cc511e78bf71c1b0daf345d
               //正好适合Servlet接收
               var tt = $(".cd").serialize();
               $.ajax({
                   url:"DaleteNoticesServlet",
                   type:"GET",
                   date:tt,
                   dateType:'test',
                   success:function (date) {
                     if (date=='false'){
                        alert('服务端返回结果说你没选中')；
                     }else {
                         alert('返回成功');
                         location.href='index.jsp';
                     }
                   },
                   error:function () {
                        alert('发生错误');
                   },
                   timeout:3000
               });
           });
            //注册点击选中checkbox事件
           $("#cdBtn").click(function () {
               var flag = $().is(':checked');
               if (falg){
                    //alert('全选');
                   if (flag){
                       //alert('全选');

                       $(".cb").attr("checked",true);
                   }
                   else{
                       //alert('取消选中');
                       $(".cb").attr("checked",false);
                   }
               }
               //1.自己是选中(a.自己不选 b.把下面checkbox也取消选中)

               //2.自己是未选中状态(a.自己选中 b.把下面checkbox也选中)
           });

           //注册点击添加按钮事件
           $("#addBtn").click(function(){
               location.href='add.jsp';
           });


           var MySuccess = function(data){
               var html = "";
               if (data.length==0){
                   $("#datanull").show();
               }

               $.each(data,function(i,notice){
                   html = html + "<tr>";


                   html = html + "<td>";
                   html = html + "<input type='checkbox' name='cb' class='cb'";

                   html = html + " value=" + notice.id;
                   html = html + ">";
                   html = html + "</td>";

                   html = html + "<td>";
                   html = html + (i+1);
                   html = html + "</td>";

                   html = html + "<td>";
                   html = html + notice.title;
                   html = html + "</td>";

                   html = html + "<td>";
                   html = html + notice.author;
                   html = html + "</td>";

                   html = html + "<td>";
                   html = html + notice.content;
                   html = html + "</td>";

                   html = html + "<td>";
                   if (notice.notice_status==1){
                       html = html + "<font color='red'>未审核</font>";
                   }else{
                       html = html + "已审核";

                   }

                   html = html + "</td>";

                   html = html + "<td>";
                   html = html + notice.public_date;
                   html = html + "</td>";

                   html = html + "<td>";
                   html = html + "<a href='DeteleNoticeServlet?id=";
                   html = html + notice.id;
                   html = html + "'>删除</a>&nbsp;";
                   html = html + "<a href='UpdateNoticeViewServlet?id=";
                   html = html + notice.id;
                   html = html + "'>编辑</a>";
                   html = html + "</td>";



                   html = html + "</tr>";
               });
               $("#mytable").append(html);
           };

           var MyError = function(){
               alert('AJAX访问后台时出错');
           }

           $.ajax({
               url:"ListAllNoticeServlet",
               type:'GET',
               //data:
               dataType:'json',
               success:MySuccess,
               timeout:3000,
               error:MyError
           });

       });

   </script>
</head>
<body>
<div>通告信息列表</div>
<div><button id="addBtn">发表通告</button></div>
<table border="1" id="mytable">
    <tr>
        <td><input type="checkbox" id="cdBtn"></td>
        <td>编号</td>
        <td>标题</td>
        <td>发布者</td>
        <td>内容</td>
        <td>状态</td>
        <td>发布时间</td>
        <td>操作</td>
    </tr>
    <tr style="display: none;" id="datenull">
        <td colspan='7'><font color='red'>数据为空</font></td>
    </tr>
</table>
<button id="delBtn">删除</button>
</body>
</html>
